package user1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 8:59
 * @description:
 */
public class User1DaoMap implements User1Dao {
  HashMap<String,user> map=new HashMap<>();

  @Override
  public void register(user user1) {
     map.put(user1.getName(),user1);
  }

  @Override
  public boolean login(String name, String Password) {
    Iterator iterator=map.keySet().iterator();
    while (iterator.hasNext()){
      String key=(String ) iterator.next();
      user value=map.get(key);
      if(name.equals(key)&&Password.equals(value.getPassword())){
        return true;
      }
    }
    return false;
  }

  @Override
  public void quereyAll() {
    System.out.println("");
    Iterator iterator=map.entrySet().iterator();
    while (iterator.hasNext()){
      Map.Entry<String,user> entry=(Map.Entry<String,user>) iterator.next();
      String key=entry.getKey();
      user value=entry.getValue();
      System.out.println(value);
    }

  }
}
